package cn.sxt.yxl.controller.head;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.yxl.common.controller.BaseController;
import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.pojo.AColumnsEnum;
import cn.sxt.yxl.question.pojo.AItems;
import cn.sxt.yxl.question.pojo.AItemsEnum;
import cn.sxt.yxl.question.pojo.AQuestion;
import cn.sxt.yxl.question.service.IQuestionService;

@Controller
public class IndexHeadController extends BaseController{
	
	@Resource
	private IQuestionService questionService;
	/**
	 * 首页
	 * @return
	 */
	@RequestMapping("/main")
	public String main(){
		return "/head/main";
	}
	/**
	 * 查询所有栏目
	 * @return
	 */
	@RequestMapping("/header")
	public String header(HttpServletRequest request){
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		//将启用的栏目全部查询出来
		condMap.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
		List<AColumns> columnsList = this.questionService.findCondListColumnsService(null, condMap);
		request.setAttribute("columnsList", columnsList);
		return "/head/header";
	}
	/**
	 * 栏目下的测试项
	 */
	@RequestMapping("/{url}")
	public String itemsList(HttpServletRequest request,@PathVariable String url){
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		condMap.put("url", url);
		//获取对应栏目
		AColumns columns = this.questionService.findOneColumnsService(condMap);
		request.setAttribute("columns", columns);
		
		condMap.clear();
		condMap.put("columnsId", columns.getId());
		condMap.put("status", AItemsEnum.STATUS_ENABLE.getStatus());
		//分页
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		List<AItems> itemsList = this.questionService.findItemsCondListService(pageInfoUtil, condMap);
		request.setAttribute("itemsList", itemsList);
		return "/head/itemsList";
	}
	/**
	 * 查询测试信息
	 */
	@RequestMapping("/items/{iid}")
	public String itemsInfo(HttpServletRequest request,@PathVariable int iid){
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		condMap.put("id", iid);
		AItems items = this.questionService.findOneItemsService(condMap);
		request.setAttribute("items", items);
		return "head/itemsInfo";
	}
	/**
	 * 查询测试项下面的问题
	 */
	@RequestMapping("/items/{iid}/start")
	public String questionList(HttpServletRequest request,@PathVariable int iid){
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		condMap.put("id", iid);
		AItems items = this.questionService.findOneItemsService(condMap);
		request.setAttribute("items", items);
		return "head/questionList";
		
	}
}
